/*
 * @Author: zoufengfan
 * @Date: 2022-07-13 14:35:05
 * @LastEditTime: 2022-07-18 15:50:24
 * @LastEditors: zoufengfan
 */
import { defineConfig } from 'yapi-to-typescript';

// 使用示例
// url: /a/b/c
// import { c } from '_api/{YAPI的ProjectName}/a/b'

export default defineConfig([
  {
    serverUrl: 'http://172.16.14.34:3001',
    // typesOnly: true,
    devEnvName: 'local',
    target: 'typescript',
    reactHooks: {
      enabled: false,
    },
    prodEnvName: 'production',
    requestFunctionFilePath: 'src/server/yapi/request.ts',
    // 对接过接口后不能随便更改
    getRequestFunctionName(interfaceInfo, changeCase) {
      let str = interfaceInfo.query_path.path.match(/(?!\/)[\w\d-{}]+$/)?.[0]; //  /a/b/c  => c
      //防止使用关键字作为函数名
      const keywords = ['import', 'export', 'require', 'delete'];
      return keywords.includes(str) ? '_' + str : str;
    },
    // 对接过接口后不能随便更改
    outputFilePath: (interfaceInfo) => {
      let path = '';
      let arr = interfaceInfo.query_path.path.split('/'); //  /a-b/{c}/d/e
      arr.length -= 1; //  /a-b/{c}/d/e  =>  /a-b/{c}/d
      path = arr.join('/');
      return `src/server/yapi/api/${interfaceInfo._project.name}${path}.ts`;
    },
    dataKey: 'data',
    projects: [
      {
        token: '39d4d59903715b9f6531ba63fb0ea7f7adfaedb35cd59724e36b6d0c4bb8bee0',
        categories: [
          {
            id: 0,
          },
        ],
      },
    ],
  },
]);
